﻿// ***********************************************************************
// Assembly         : SecurityLayer
// Author           : LJO+01 (Laurent Jordi)
// Created          : 06-05-2013
// Last Modified By : LJO+01 (Laurent Jordi)
// Last Modified On : 06-05-2013
// ***********************************************************************
// <copyright file="LogOffController.cs" company="Copyright © Innovacall 2011">
//     Copyright (c) Copyright © Innovacall 2011. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
using System.Web.Mvc;
using System.Web.Routing;
using InnovaApp.Layers.SecurityLayer.Models.AccountModels.MembershipServices;

namespace InnovaApp.Layers.SecurityLayer.Controllers
{
    /// <summary>
    /// Class LogOffController
    /// </summary>
	public class LogOffController : Controller
	{
        /// <summary>
        /// Gets or sets the forms service.
        /// </summary>
        /// <value>The forms service.</value>
		public IFormsAuthenticationService FormsService { get; set; }
        /// <summary>
        /// Gets or sets the membership service.
        /// </summary>
        /// <value>The membership service.</value>
		public IMembershipService MembershipService { get; set; }

        /// <summary>
        /// Initializes data that might not be available when the constructor is called.
        /// </summary>
        /// <param name="requestContext">The HTTP context and route data.</param>
		protected override void Initialize(RequestContext requestContext)
		{
			if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
			if (MembershipService == null) { MembershipService = new AccountMembershipService(); }

			base.Initialize(requestContext);
		}

		#region LogOff
        /// <summary>
        /// URL: /LogOff
        /// </summary>
        /// <returns>ActionResult.</returns>
		[Authorize]
		public ActionResult Index()
		{
			FormsService.SignOut();
			Session.Abandon();
			return RedirectPermanent("~/");
		}

		#endregion
	}
}
